// ml:run = $bin < input
#include <iostream>
#include <vector>
#include <utility>

int n, m;
std::vector<std::vector<int>> a;
std::vector<std::vector<int>> b;
using pair = std::pair<int, int>;
std::vector<pair> q;

void init()
{
    a.clear(); a.resize(n + 1);
    b.clear(); b.resize(n + 1);
}

bool inrange(int x, pair const& a)
{
    return a.first <= x && x <= a.second;
}

bool judge()
{
    for (int i = 1; i <= n; i++)
        if (a[i].size() != b[i].size()) return false;
    for (int i = 1; i <= n; i++) {
        for (size_t j = 0; j < a[i].size(); j++) {
            auto t1 = a[i][j];
            auto t2 = b[i][j];
            for (int t = 0; t < m; t++) {
                if (t1 == t2) break;
                if (!inrange(t1, q[t])) continue;
                if (inrange(t2, q[t]))
                    t1 = t2;
                else if (t2 < q[t].first)
                    t1 = q[t].first;
                else
                    t1 = q[t].second;
            }
            if (t1 != t2) return false;
        }
    }
    return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int T; std::cin >> T;
    while (T--) {
        std::cin >> n >> m;
        init();
        for (int i = 1, x; i <= n; i++) {
            std::cin >> x;
            if (x) a[x].push_back(i);
        }
        for (int i = 1, x; i <= n; i++) {
            std::cin >> x;
            if (x) b[x].push_back(i);
        }
        q.clear(); q.resize(m);
        for (int i = 0; i < m; i++) std::cin >> q[i].first >> q[i].second;

        if (judge()) std::cout << "Yes\n";
        else std::cout << "No\n";
    }
}

